﻿<Window x:Class="Microsoft.Forums.ForumsClient.SubscribeToForums"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ForumClient="clr-namespace:Microsoft.Forums.ForumsClient"
    xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase" 
    xmlns:ForumsOfflineStore="clr-namespace:Microsoft.Forums.OfflineStore;assembly=ForumsOfflineStore" 
    x:Uid="SubscribeToForumsTitle"
    WindowStartupLocation="CenterScreen" 
    Style="{DynamicResource DialogWindowStyle}"
    Title="Subscribe to Forums" MinHeight="600" MinWidth="600" Height="750" Width="700" >
    
    <Window.Resources>
        <!-- These resources will instantiate the classes used by various controls -->
        <ForumClient:PreviewForumsCollection x:Uid="ForumClient:previewForums" x:Key="previewForums"/>
        <ForumClient:BrandsCollection x:Uid="ForumClient:forumsBrands" x:Key="forumsBrands"/>
        <ForumClient:BrandForumsCollection x:Uid="ForumClient:availableForums" x:Key="availableForums" />
        <ForumClient:LocaleCollection x:Uid="ForumClient:availableLocales" x:Key="availableLocales" />
        <ForumClient:IsPublicForumVisible x:Key="IsThisForumPublic" />
        <BooleanToVisibilityConverter x:Key="IsThisForumNew" />
        <BooleanToVisibilityConverter x:Key="IsThisUserModerator" />
         
        
        <DataTemplate x:Key="NewIconTemplate">
            <Image x:Uid="NewIconTemplateImage" Margin="0,6,0,5" Width="16" Height="16" Source="pack://application:,,,/images/BlueNew.ico" Visibility="{Binding Path=IsNewForum, Converter={StaticResource IsThisForumNew}}" Name="NewIconTemplateImage" ToolTip="New forum since you last used this dialog." />
        </DataTemplate>

        <DataTemplate x:Key="ModeratorIconTemplate">
            <Image x:Uid="ModeratorIconTemplateImage" Margin="0,5,0,5" Height="16" Width="16" Source="pack://application:,,,/images/Moderator.ico" Name="ModeratorIconImage" Visibility="{Binding Path=IsModerator, Converter={StaticResource IsThisUserModerator}}" ToolTip="You are a moderator in this forum." />
        </DataTemplate>
        
        <DataTemplate x:Key="PublicForumIconIconTemplate">
            <Image x:Uid="PublicForumIconIconTemplateImage" Margin="0,6,0,5" Height="24" Width="24" Source="pack://application:,,,/images/BlueUnlocked.ico" Name="PublicForumIconImage" Visibility="{Binding Path=IsPrivate, Converter={StaticResource IsThisForumPublic}}" ToolTip="This is a public forum." />
        </DataTemplate>
        
        <DataTemplate x:Key="DescriptionExpanderTemplate">
            <Expander  Width="340" IsExpanded="False" Header="{Binding Path=Description}"  >
                <TextBlock x:Uid="ForumDetailsTemplateDescriptionTextBlock" Text="{Binding Path=Description}" TextWrapping="Wrap" />
			</Expander>
        </DataTemplate>
        
        <DataTemplate x:Key="AvailableForumNameTemplate" >
            <TextBlock Text="{Binding Path=DisplayName}" />
        </DataTemplate>
        
        <!-- BrandsCollectionViewSource -->
        <CollectionViewSource x:Uid="BrandsCollectionViewSource" x:Key="BrandsCollectionViewSource" Source="{Binding Source={StaticResource forumsBrands}, Path=BrandCollection}"  >
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription    x:Uid="scm:BrandsCollectionViewSourceSortDescription"  PropertyName="BrandName"/>
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
        
        <!-- LocaleCollectionViewSource -->
        <CollectionViewSource x:Uid="LocaleCollectionViewSource" x:Key="LocaleCollectionViewSource" Source="{Binding Source={StaticResource availableLocales}, Path=AvailableLocalesCollection}"  >
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription   x:Uid="scm:LocaleCollectionViewSourceSortDescription" PropertyName="LocaleName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
        
        <!-- PreviewCollectionViewSource -->
        <CollectionViewSource x:Uid="PreviewCollectionViewSource" x:Key="PreviewCollectionViewSource" Source="{Binding Source={StaticResource previewForums}, Path=Instance}"  >
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription   x:Uid="scm:PreviewCollectionViewSourceSortDescription" PropertyName="DisplayName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <!-- BrandForumsCollectionViewSource -->
        <CollectionViewSource x:Uid="BrandForumsCollectionViewSource" x:Key="BrandForumsCollectionViewSource" Source="{Binding Source={StaticResource availableForums}, Path=AvailableForumsCollection}"  >
            <CollectionViewSource.SortDescriptions>
                <scm:SortDescription   x:Uid="scm:BrandForumsCollectionViewSourceSortDescription" PropertyName="DisplayName" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>
    </Window.Resources>

    <Grid  x:Uid="LayoutRoot" Name="LayoutRoot">
        <Image x:Uid="background"  Margin="0,0,-337.333,-171.333" x:Name="background" Style="{DynamicResource BackgroundStyle}" Stretch="Fill"/>
        <Grid  x:Uid="Grid_1" Margin="10,10,10,15" >
            <Grid.RowDefinitions>
                <RowDefinition x:Uid="RowDefinition_0" Height="Auto"/>
                <RowDefinition  Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_1" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_2" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_3" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_4" Height="*"/>
                <RowDefinition x:Uid="RowDefinition_5" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_6" Height="Auto"/>
                <RowDefinition x:Uid="RowDefinition_7" Height="Auto"/>
            </Grid.RowDefinitions>

            <Grid Grid.Row="0" HorizontalAlignment="Stretch" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Label Grid.Row="0" FontSize="16" FontWeight="Bold" Content="Subscribe to Forums" HorizontalAlignment="Center" Style="{DynamicResource DialogLabelHighLightStyle}" />
            </Grid>

            <Grid Grid.Row="1" HorizontalAlignment="Stretch" >
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Label Content="Set Your Preferences and Filters" Grid.Row="0" Style="{DynamicResource DialogLabelHighLightStyle}" />
            </Grid>

            <!-- Filter Grid -->
            <Grid x:Uid="Grid_2" Grid.Row="2" HorizontalAlignment="Stretch" Background="White">
                <Grid.RowDefinitions>
                    <RowDefinition  Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Uid="ColumnDefinition_1" Width="0.39*" />
                    <ColumnDefinition x:Uid="ColumnDefinition_2" Width=".175*" />
                    <ColumnDefinition x:Uid="ColumnDefinition_3" Width=".175*" />
                    <ColumnDefinition x:Uid="ColumnDefinition_4" Width="Auto" />
                </Grid.ColumnDefinitions>

                <StackPanel x:Uid="StackPanel_14" Orientation="Horizontal" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Top">

                    <Label x:Uid="FilterLabel" Height="25" Margin="5" Name="FilterLabel" Content="Filter Name and Description" ToolTip="Case insensitively restricts display to forums that contain the search text in their name or description." />
                    <TextBox x:Uid="FilterTextBox" Name="FilterTextBox" Height="25" Width="110" IsEnabled="False" TextChanged="FilterTextBox_TextChanged" ToolTip="Case insensitively restricts display to forums that contain the search text in their name or description." />
                </StackPanel>
                <StackPanel x:Uid="StackPanel_15" Orientation="Horizontal" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Top">

                    <Label x:Uid="BrandLabel" Height="25" Margin="5" Name="BrandLabel" Content="Brand" ToolTip="Display forums for a technology area" />
                    <ComboBox IsEnabled="False" x:Uid="BrandComboBox" Height="25" Margin="0,5,5,5" SelectedIndex="-1" Name="BrandComboBox" ItemsSource="{Binding Source={StaticResource BrandsCollectionViewSource}}" MinWidth="70" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" SelectionChanged="BrandOrLocaleComboBox_SelectionChanged" ToolTip="Display forums for a technology area">
                    </ComboBox>
                </StackPanel>
                <StackPanel x:Uid="StackPanel_16" Orientation="Horizontal" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                    <Label x:Uid="LocaleLabel" Height="25" Margin="5" Name="LocaleLabel" Content="Locale"  ToolTip="Display forums available in a particular locale"/>
                    <ComboBox x:Uid="LocaleComboBox" Height="25" Margin="0,5,5,5" SelectedIndex="-1" Name="LocaleComboBox" IsEnabled="False" ItemsSource="{Binding Source={StaticResource LocaleCollectionViewSource}}"  MinWidth="70" IsReadOnly="True" IsSynchronizedWithCurrentItem="True" SelectionChanged="BrandOrLocaleComboBox_SelectionChanged" ToolTip="Display forums available in a particular locale" >
                    </ComboBox>
                </StackPanel>
                <StackPanel x:Uid="StackPanel_17" Orientation="Horizontal" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Top">
                    <Label x:Uid="ShowLabel" Height="25" Margin="5" Name="ShowLabel" Content="Show"  />
                    <ComboBox x:Uid="ShowComboBox" IsEnabled="False" IsSynchronizedWithCurrentItem="True" Width="40" Margin="0,5,5,5" Height="25" SelectedIndex="0" Name="ShowComboBox">
                        <ComboBoxItem x:Uid="AllComboBoxItem" Content="All"/>
                        <ComboBoxItem x:Uid="NewComboBoxItem" Content="New"/>
                    </ComboBox>
                </StackPanel>
            </Grid>

            <!-- Settings Grid -->
            <Grid x:Uid="Grid_3" Grid.Row="3" HorizontalAlignment="Stretch" Background="White">
                <Grid.RowDefinitions>
                    <RowDefinition x:Uid="RowDefinition_9" Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition x:Uid="ColumnDefinition_5" Width="0.35*" />
                    <ColumnDefinition x:Uid="ColumnDefinition_6" Width=".32*" />
                    <ColumnDefinition x:Uid="ColumnDefinition_7" Width="Auto" />
                </Grid.ColumnDefinitions>
                <StackPanel x:Uid="StackPanel_18" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Stretch"  Orientation="Horizontal" >
                    <Label x:Uid="DaysLabel" Height="25" Margin="5" Name="DaysLabel" Content="Days of Threads in Initial Download" ToolTip="First download will include threads with activity in the past N days. In subsequent synchronizations, you get all posts since you last synchronized." />
                    <ComboBox x:Uid="DaysComboBox" IsEnabled="False" IsSynchronizedWithCurrentItem="True" MinWidth="50" Margin="5,10,5,10" Height="25" SelectedIndex="1" Name="DaysComboBox" ToolTip="First download will include threads with activity in the past N days. In subsequent synchronizations, you get all posts since you last synchronized." >
                        <ComboBoxItem x:Uid="Days1ComboBoxItem" Content="1"/>
                        <ComboBoxItem x:Uid="Days7ComboBoxItem" Content="7"/>
                        <ComboBoxItem x:Uid="Days30ComboBoxItem" Content="30"/>
                        <ComboBoxItem x:Uid="Days60ComboBoxItem" Content="60"/>
                        <ComboBoxItem x:Uid="Days90ComboBoxItem" Content="90"/>

                    </ComboBox>
                </StackPanel>
                <StackPanel x:Uid="StackPanel_19" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch"   >
                    <Label x:Uid="Label_1" Margin="0" Width="50"></Label>
                    <Button x:Uid="SyncOptionsButton" IsEnabled="False" Width="150"  Name="SyncOptionsButton"  Style="{DynamicResource DialogButtonStyle}" >Advanced Sync Settings</Button>
                    <Label x:Uid="Label_2" Margin="0" Width="50"></Label>
                </StackPanel>
                <StackPanel x:Uid="StackPanel_20" Grid.Row="0" Grid.Column="2" HorizontalAlignment="Stretch"   >

                    <CheckBox x:Uid="CategoryCheckBox" Name="CategoryCheckBox" IsEnabled="False"  Margin="5,16,5,13" VerticalAlignment="Bottom" Content="Group by categories"  />
                </StackPanel>
            </Grid>

            <!-- Available Forums header Stack Panel -->
            <StackPanel  x:Uid="StackPanel_21" Margin="5,0,5,0" Grid.Row="4">
                <StackPanel x:Uid="StackPanel_22" Orientation="Horizontal" Margin="0,5,0,5">
                    <Label x:Uid="AvailableLabel" Padding="0" Name="AvailableLabel" Style="{DynamicResource DialogLabelHighLightStyle}" />
                    <Label x:Uid="AvailableBrandForumsLabel" Padding="0" Name="AvailableBrandForumsLabel" FontWeight="Bold" Style="{DynamicResource DialogLabelHighLightStyle}" />
                    <Label x:Uid="ForumsLocaleLabel" Padding="0" Name="ForumsLocaleLabel" Style="{DynamicResource DialogLabelHighLightStyle}" />
                    <Label x:Uid="SelectedLocaleLabel" Padding="0" Name="SelectedLocaleLabel" Style="{DynamicResource DialogLabelHighLightStyle}" FontWeight="Bold" />
                    <Label x:Uid="NotSubscribedLabel" Padding="0" Name="NotSubscribedLabel" Style="{DynamicResource DialogLabelHighLightStyle}" />
                </StackPanel>

            </StackPanel>

            <!-- Available forums List -->
            <ListView Grid.Row="5" x:Uid="AvailableForumsListBox" 
                      ItemsSource="{Binding Source={StaticResource BrandForumsCollectionViewSource}}" 
				      HorizontalAlignment="Stretch" 
                      VerticalAlignment="Stretch" 
                      SelectionChanged="AvailableForumsListBox_SelectionChanged" 
                      Name="AvailableForumsListBox" SelectedIndex="-1" 
                      ScrollViewer.VerticalScrollBarVisibility="Auto" 
                      IsSynchronizedWithCurrentItem="True" 
                      Margin="-1,0,-1,0" >
                <ListView.View>
                    <GridView>
                        <GridViewColumn   CellTemplate="{StaticResource NewIconTemplate}" />
                        <GridViewColumn Header="Forum Name" Width="200" CellTemplate="{StaticResource AvailableForumNameTemplate}" />
                        <GridViewColumn   CellTemplate="{StaticResource ModeratorIconTemplate}" />
                        <GridViewColumn   CellTemplate="{StaticResource PublicForumIconIconTemplate}" />
                        <GridViewColumn Header="Description" CellTemplate="{StaticResource DescriptionExpanderTemplate}"/>
                    </GridView>
                </ListView.View>
            </ListView>
            
            <!-- Add button StackPanel -->
            <StackPanel x:Uid="StackPanel_24" Grid.Row="6">
                <StackPanel x:Uid="StackPanel_13" Background="White">
                    <Button  IsEnabled="False" HorizontalAlignment="Right" Name="AddButton" x:Uid="AddButton" Width="50" Click="AddForumToPreviewArea" ToolTip="Adds Forum to Preview Area" Style="{DynamicResource DialogButtonStyle}" >Add</Button>
                </StackPanel>
            </StackPanel>

            <!-- Subscription Preview Area StackPanel -->
            <StackPanel x:Uid="StackPanel_25" Margin="0,5,0,15" Grid.Row="7">
                <Label Name="SubscriptionPreviewAreaLabel" x:Uid="SubscriptionPreviewAreaLabel" Padding="5,0,0,0" Style="{DynamicResource DialogLabelHighLightStyle}" VerticalAlignment="Center" ToolTip="Forums you selected for subscription.">Forum Subscription Preview List </Label>
                <ListView x:Uid="PreviewForumsListBox" Height="150" 
                          ItemsSource="{Binding Source={StaticResource PreviewCollectionViewSource}}" 
				          SelectionChanged="PreviewForumsListBox_SelectionChanged" 
                          Name="PreviewForumsListBox" SelectedIndex="-1" 
                          ScrollViewer.VerticalScrollBarVisibility="Auto" 
                          IsSynchronizedWithCurrentItem="True" 
                          Margin="-1,0,-1,0" >
                    <ListView.View>
                        <GridView>
                            <GridViewColumn   CellTemplate="{StaticResource NewIconTemplate}" />
                            <GridViewColumn Header="Forum Name" Width="200"  DisplayMemberBinding="{Binding Path=DisplayName}"/>
                            <GridViewColumn   CellTemplate="{StaticResource ModeratorIconTemplate}" />
                            <GridViewColumn   CellTemplate="{StaticResource PublicForumIconIconTemplate}" />
                            <GridViewColumn Header="Description" CellTemplate="{StaticResource DescriptionExpanderTemplate}"/>
                        </GridView>
                    </ListView.View>
                </ListView>
                <StackPanel x:Uid="StackPanel_26" Background="White">
                    <Button IsEnabled="False" HorizontalAlignment="Right" x:Uid="RemoveButton" Name="RemoveButton" Click="RemoveForumFromPreviewArea" Width="60" ToolTip="Removes the selected Forum from Preview Area" Style="{DynamicResource DialogButtonStyle}" >Remove</Button>
                </StackPanel>
            </StackPanel>

            <!-- Finish & Cancel Buttons StackPanel-->
            <StackPanel x:Uid="StackPanel_27" Grid.Row="8" Background="White">
                <StackPanel x:Uid="StackPanel_28" Orientation="Horizontal"  HorizontalAlignment="Right" >
                    <Label Name="FinishLabel" Content="To complete the subscription process, you must click Finish." />
                    <Button x:Uid="FinishButton" Name="FinishButton" IsEnabled="False" Content="Finish" Width="40" ToolTip="Click this button to subscribe to forums listed in the Subscription Preview Area" Click="FinishButton_Click"  Style="{DynamicResource DialogButtonStyle}" />
                    <Button x:Uid="CancelButton" Name="CancelButton" IsEnabled="False" IsCancel="True" Style="{DynamicResource DialogButtonStyle}" Width="50" Click="CancelButton_Click" >Cancel</Button>
                </StackPanel>
            </StackPanel>

        </Grid>
    </Grid>

</Window>
